package com._dev.social.service.impl;

import com._dev.social.mapper.CommentsMapper;
import com._dev.social.mode.domain.Comments;
import com._dev.social.mode.domain.request.CommentsRequest;
import com._dev.social.mode.domain.response.CommentWithUserDTO;
import com._dev.social.service.CommentsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Administrator
 * @description 针对表【comments】的数据库操作Service实现
 * @createDate 2024-11-09 14:05:37
 */
@Service
public class CommentsServiceImpl extends ServiceImpl<CommentsMapper, Comments>
        implements CommentsService {
    @Resource
    private CommentsMapper commentsMapper;

    @Override
    public void saveComment(CommentsRequest comment) {
        Comments comments = new Comments();
        comments.setUid(comment.getUid());
        comments.setTid(Long.valueOf(comment.getTid()));
        comments.setContent(comment.getContent());
        try {
            this.save(comments);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public List<CommentWithUserDTO> getCommentsWithUserByPostId(Long postId) {
        return commentsMapper.getCommentsWithUserByPostId(postId);
    }

    @Override
    public List<CommentWithUserDTO> getAllThreadCommentByUserId(String userId) {
        return commentsMapper.getAllThreadCommentByUserId(userId);
    }

}




